<?php
/**
 * Created by PhpStorm.
 * User: Mysic
 * Date: 2021/1/9
 * Time: 15:13
 */

namespace app\common\mysic\profitShare\procedures;


use app\common\model\divide\Store;
use app\common\model\divide\System;
use app\common\mysic\MysicBase;
use app\common\service\Order as OrderService;

class RuntimeVariables extends MysicBase
{
    /*** @var string 分红微股东总数 */
    protected static $receivesAmount = 0;
    /*** @var string 分红上限金额 */
    protected static $profitUpperLimit = '0.00';
    /*** @var string 分红金额总和 */
    protected static $profitAmount = '0.00';
    /*** @var string 分红金额 */
    protected static $profit = '0.00';
    /*** @var int 分红金额的存留的账户类型 */
    protected static $bonusType;// 1 退款到微信  2 退款到赏金 3 退款到零钱
    /*** @var string 调用微信分账接口分账接口专用号 */
    protected static $profitShareSn = '';
    /*** @var array 调用微信添加分帐人接口返回值 */
    protected static $wxProfitShareAddReceiverResponse = [];
    /*** @var array 调用微信分账申请接口返回值 */
    protected static $wxProfitSharingApplyResponse = [];
    /*** @var array 调用微信分账查询接口返回值 */
    protected static $wxProfitSharingQueryResponse = [];
    /*** @var array 调用微信删除分帐人接口返回值*/
    protected static $wxProfitShareRemoveReceiverResponse = [];
    /*** @var array 调用微信完结分账接口返回值 */
    protected static $wxFinishProfitSharingResponse = [];
    /*** @var System  平台分账订单实体 */
    protected static $systemProfitOrderEntity;
    /*** @var array 服务商分账订单实体数组 */
    protected static $serviceProfitOrderEntities;
    /*** @var Store 商户分账订单实体 */
    protected static $storeProfitOrderEntity;
    /*** @var array 微股东的分红订单实体数组 */
    protected static $receiveEntities = [];
    /*** @var array 微股东的分红订单分红流水实体数组 */
    protected static $receiveLogEntities = [];
    /*** @var array 已结束分红信息实体数组 */
    protected static $finishedReceivesEntities = [];
    /*** @var array 已结束分红流水信息实体数组 */
    protected static $finishedReceivesLogEntities = [];
    /*** @var array 分账申请中的分账接收人列表 */
    protected static $profitSharingReceivers = [];
    /*** @var array 添加分账接收人接口的服务商分账人信息 */
    protected static $systemProfitSharingReceiver = [];
    /*** @var array 参与分红的订单所属用户信息 */
    protected static $userEntities = [];
    /*** @var array 参与分红的订单实体 */
    protected static $receiveOrderEntities = [];
    /**
     * 设置微股东总数
     * @param $amount int 分红微股东总数
     * @return bool
     */
    public static function setReceivesAmount(int $amount): bool
    {
        self::$receivesAmount = $amount;
        return true;
    }
    /**
     * 返回分红微股东总数
     * @return int 总数量
     */
    public static function getReceivesAmount()
    {
        return self::$receivesAmount;
    }

    /**
     * 设置分红金额上限数
     * @param $profitUpperLimit
     * @return bool
     */
    public static function setProfitUpperLimit($profitUpperLimit): bool
    {
        self::$profitUpperLimit = $profitUpperLimit;
        return true;
    }

    public static function getProfitUpperLimit(): string
    {
        return self::$profitUpperLimit;
    }

    public static function setProfitAmount($profitAmount): bool
    {
        self::$profitAmount = $profitAmount;
        return true;
    }

    public static function getProfitAmount(): string
    {
        return self::$profitAmount;
    }

    public static function setProfit($profit): bool
    {
        self::$profit = $profit;
        return true;
    }
    /**
     * 获取分红金额
     * @return string 分红金额
     */
    public static function getProfit(): string
    {
        return self::$profit;
    }
    /**
     * 设置分红金额的存留的账户类型
     * @param $bonusType int 分红金额的存留的账户类型  1 微信 2 赏金 3 零钱
     * @return bool
     */
    public static function setBonusType(int $bonusType): bool
    {
        self::$bonusType = $bonusType;
        return true;
    }

    public static function getBonusType(): int
    {
        return self::$bonusType;
    }

    public static function createProfitShareSn($isRefund = false): string
    {
        $prefix = 'P';
        $isRefund && $prefix = 'R';
        return self::$profitShareSn = $prefix . OrderService::createOrderNo();
    }

    public static function getProfitShareSn(): string
    {
        return self::$profitShareSn ?? '';
    }

    public static function setWxProfitShareAddReceiverResponse(array $response): bool
    {
        self::$wxProfitShareAddReceiverResponse = [];
        self::$wxProfitShareAddReceiverResponse[] = $response;
        return true;
    }

    public static function getWxProfitShareAddReceiverResponse(): array
    {
        return self::$wxProfitShareAddReceiverResponse;
    }

    public static function setWxProfitSharingApplyResponse(array $response): bool
    {
        self::$wxProfitSharingApplyResponse = $response;
        key_exists('refund_id', $response) && self::$wxProfitSharingApplyResponse['profit_id'] = $response['refund_id'];
        key_exists('order_id', $response) && self::$wxProfitSharingApplyResponse['profit_id'] = $response['order_id'];
        return true;
    }

    public static function getWxProfitSharingApplyResponse(): array
    {
        return self::$wxProfitSharingApplyResponse;
    }

    public static function setWxProfitSharingQueryResponse(array $response):bool
    {
        self::$wxProfitSharingQueryResponse = $response;
        return true;
    }

    public static function getWxProfitSharingQueryResponse(): array
    {
        return self::$wxProfitSharingQueryResponse;
    }

    public static function setSystemProfitOrderEntity($entity): bool
    {
        self::$systemProfitOrderEntity = $entity;
        return true;
    }

    public static function getSystemProfitOrderEntity(): System
    {
        return self::$systemProfitOrderEntity;
    }

    public static function setServiceProfitOrderEntities(array $entities): bool
    {
        self::$serviceProfitOrderEntities = $entities;
        return true;
    }

    public static function getServiceProfitOrderEntities(): array
    {
        return self::$serviceProfitOrderEntities;
    }

    public static function setStoreProfitOrderEntity($entity):bool
    {
        self::$storeProfitOrderEntity = $entity;
        return true;
    }

    public static function getStoreProfitOrderEntity(): Store
    {
        return self::$storeProfitOrderEntity;
    }

    public static function setReceivesEntities(array $receivesEntities):bool
    {
        self::$receiveEntities = [];
        foreach($receivesEntities as $entity) {
            self::$receiveEntities[$entity->order_no] = $entity;
        }
        return true;
    }
    /**
     * @return array self::$receiveEntities 微股东的分红订单实体数组
     */
    public static function getReceivesEntities(): array
    {
        return self::$receiveEntities;
    }

    public static function setReceivesLogEntities(array $receivesLogEntities):bool
    {
        self::$receiveLogEntities = [];
        foreach($receivesLogEntities as $entity) {
            self::$receiveLogEntities[$entity->receives_order_no] = $entity;
        }
        return true;
    }

    public static function getReceivesLogEntities(): array
    {
        return self::$receiveLogEntities;
    }

    public static function setFinishedReceivesEntities(array $entities): bool
    {
        self::$finishedReceivesEntities = $entities;
        return true;
    }

    public static function getFinishedReceivesEntities(): array
    {
        return self::$finishedReceivesEntities;
    }

    public static function setFinishedReceivesLogEntities(array $entities): bool
    {
        self::$finishedReceivesLogEntities = $entities;
        return true;
    }

    public static function getFinishedReceivesLogEntities(): array
    {
        return self::$finishedReceivesLogEntities;
    }

    public static function setWxProfitShareRemoveReceiverResponse(array $response): bool
    {
        self::$wxProfitShareRemoveReceiverResponse = $response;
        return true;
    }

    public static function getWxProfitShareRemoveReceiverResponse(): array
    {
        return self::$wxProfitShareRemoveReceiverResponse;
    }

    public static function setWxFinishProfitSharingResponse(array $response)
    {
        self::$wxFinishProfitSharingResponse = $response;
    }

    public static function getWxFinishProfitSharingResponse(): array
    {
        return self::$wxFinishProfitSharingResponse;
    }

    public static function setProfitSharingReceivers($receivers)
    {
        self::$profitSharingReceivers = $receivers;
    }

    public static function getProfitSharingReceivers(): array
    {
        return self::$profitSharingReceivers;
    }

    public static function setUserEntities($userEntities)
    {
        self::$userEntities = $userEntities;
    }

    public static function getUserEntities(): array
    {
        return self::$userEntities;
    }

    public static function setReceiveOrderEntities($receiveOrderEntities)
    {
        self::$receiveOrderEntities = $receiveOrderEntities;
    }

    public static function getReceiveOrderEntities(): array
    {
        return self::$receiveOrderEntities;
    }

}